package com.zhkj.txg.module.mine.ui

import android.view.View
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import com.zhkj.lib.base.ViewModelActivity
import com.zhkj.lib.http.HttpResponseStatus
import com.zhkj.txg.R
import com.zhkj.txg.module.mine.adapter.HelpAdapter
import com.zhkj.txg.module.mine.vm.SettingViewModel
import kotlinx.android.synthetic.main.activity_guide_list.*

class GuideListActivity : ViewModelActivity<SettingViewModel>() {

    private val helpAdapter = HelpAdapter()

    override fun setViewModel(): SettingViewModel = createViewModel()
    override fun statusTitleBar(): View? = titleHelp
    override val layoutResId: Int = R.layout.activity_guide_list

    override fun initUI() {
        with(rvHelp) {
            layoutManager = LinearLayoutManager(this@GuideListActivity)
            adapter = helpAdapter
        }
        refreshHelp.setOnRefreshListener { initData() }
    }

    override fun initData() {
        viewModel.guideList()
    }

    override fun initViewModel() {
        viewModel.guideListLiveData.observe(this, Observer { response ->
            if (response.status == HttpResponseStatus.Status.SUCCESS) response.response?.data?.let {
                helpAdapter.setNewData(it)
            }
        })
    }
}